#ifndef BUTTON_H_
#define BUTTON_H_

enum BUTTON_PIN {
	BTN_LAMP_TEST = 0x02,//GPIO_PIN1,
	BTN_WARNING = 0x04,//GPIO_PIN2,
	BTN_SERVICE_MODE = 0x08,//GPIO_PIN3,
	BTN_RESET = 0x10,//GPIO_PIN4,
	BTN_GA_ON = 0x20,//GPIO_PIN5,
	BTN_GA_OFF = 0x40,//GPIO_PIN6,
	BTN_ACK = 0x80//GPIO_PIN7
};

enum evt_e {
	eBtnReset,
	eBtnAck,
	eBtnGAoff,
	eBtnGAon,
	eBtnLampTest,
	eBtnWarning,
	eBtnSvcMode,
	eNumEvents
};
enum EvtState {
	evt_no,
	evt_yes
};

#define BTN_DEBUG 0
#define BTN_MSPWARE 0 // 1 for MSPWARE, 0 for Traditional
#define BTN_MASK_OK 1 // 1 for masking ok, ie initializing peripheral all at once, 0 for initializing each pin sequentially

struct btn_debounce {
	unsigned int unpressed_cnt;
	unsigned int pressed_cnt;
	unsigned char last;
	unsigned char mask;
	unsigned int eventCounts;
	unsigned int lockout_cnt;
	unsigned char newTurn;
	unsigned char event;
	unsigned char current;
};
struct event_s {
//	enum evt evt;
	enum EvtState evtData;
	struct btn_debounce * btn;
};
struct evtArr_s {
	struct event_s evt[eNumEvents];
/*	struct event_s eBtnReset;
	struct event_s eBtnAck;
	struct event_s eBtnGAoff;
	struct event_s eBtnGAon;
	struct event_s eBtnLampTest;
	struct event_s eBtnWarning;
	struct event_s eBtnSvcMode;*/
};

extern struct evtArr_s btnEvents;
//extern struct btn_debounce ACK, RESET, LAMP;
void BTN_init(void);
void BTN_btnDebounce_init(/*struct btn_debounce *btn, */unsigned char mask, unsigned int eventCounts, enum evt_e event);
void BTN_btnEvent_init(void);
void BTN_btnEvent_process(void);
enum EvtState BTN_btnEvent_get(enum evt_e evt);
void BTN_btnEvent_testSet(enum evt_e evt, enum EvtState state);
void BTN_btnEvent_consume(enum evt_e evt);
void BTN_btnEvent_clearAckReset(void);
void BTN_btnEvent_clearGAbtns(void);
//unsigned char SI_ackBtnLogic(void);
//unsigned char event_btn_debounce(struct btn_debounce *btn);

#endif /* BUTTON_H_ */
